var can1;
var can2;

var ctx1;
var ctx2;

var lastTime;
var deltaTime;

var bgPic=new Image();

var canHeight;
var canWidth;

var fruit;
var mam;

var mx;
var my;

var baby;

var babyTails=[];
var babyEye=[];
var babyBody=[];

var mamTails=[];
var mamEye=[];
var mamBody=[];
var mamBlueBody=[];

var data;

var wave;

var halo;

var dust;
var dustPic=[]; 
document.body.onload=game;
function game()
{
	init();
	lastTime=Date.now();
	deltaTime=0;
	gameloop();
}
function init () {
	
	can1=document.getElementById("canvas1")
	ctx1=can1.getContext("2d");
	
	can2=document.getElementById("canvas2") //background
	ctx2=can2.getContext("2d");

	bgPic.src="src/background.jpg"
	canWidth=can1.width;
	canHeight=can1.height;

	mx=canWidth*0.5;
	my=canHeight*0.5;

	for(var i=0;i<8;i++)
	{
		babyTails[i]=new Image();
		babyTails[i].src="src/bigTail"+i+".png";
	}
	for(var i=0;i<2;i++)
	{

		babyEye[i]=new Image();		
		babyEye[i].src="src/babyEye"+i+".png";
	}
	for(var i=0;i<20;i++)
	{

		babyBody[i]=new Image();		
		babyBody[i].src="src/babyFade"+i+".png";
	}

	for(var i=0;i<8;i++)
	{
		mamTails[i]=new Image();
		mamTails[i].src="src/bigTail"+i+".png";
	}
	for(var i=0;i<2;i++)
	{

		mamEye[i]=new Image();		
		mamEye[i].src="src/bigEye"+i+".png";
	}
	for(var i=0;i<8;i++)
	{

		mamBody[i]=new Image();	

		mamBody[i].src="src/bigSwim"+i+".png";

		mamBlueBody[i]=new Image();	

		mamBlueBody[i].src="src/bigSwimBlue"+i+".png";
	}
		
	for(var i=0;i<7;i++)
	{
		dustPic[i]=new Image();
		dustPic[i].src="src/dust"+i+".png";
	}
	

	ctx1.fillStyle="white";
	ctx1.font="30px Verdana";
	ctx1.textAlign="center";  //left  center  right

	can1.addEventListener("mousemove",onmousemove,false);

	ane=new aneObj();
	ane.init();

	fruit=new fruitObj();
	fruit.init();

	mam=new mamObj();
	mam.init();

	baby=new babyObj();
	baby.init();

	data=new dataObj();

	wave=new waveObj();
	wave.init();

	halo=new haloObj();
	halo.init();

	dust=new dustObj();
	dust.init();

	

}
function gameloop()
{
	window.requestAnimFrame(gameloop);
	var now=Date.now();
	
	deltaTime=now-lastTime;
	lastTime=now;
	if(deltaTime>40)
	{
		deltaTime=40;
	}
	drawBackground();
	ane.draw();
	fruitMonitor();
	fruit.draw();


	fruitMonitor();
	
	ctx1.clearRect(0,0,canWidth,canHeight);
	mam.draw();

	baby.draw();

	monFruitsCollision();
	mombabyCollision();

	data.draw();

	wave.draw();

	halo.draw();

	dust.draw();
	
}
function onmousemove(e)
{
	if(!data.gameover)
	{
		if(e.offsetX||e.layerX)
		{
			mx=e.offSetX==undefined?e.layerX:e.offSetX;
			
			my=e.offSetY==undefined?e.layerY:e.offSetY;
			
		}
	}

	
	
}